package com.wits.platform.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.custom.ResourceDaoCustom;
import com.wits.platform.dto.ResourceDTO;
import com.wits.platform.entity.Resource;

@Component
public class ResourceDaoImpl extends BaseDaoImpl<Resource,String> implements ResourceDaoCustom{

	@Override
	public void deleteInBatch(String ids) {
		String sql="delete from wits_resource r where r.rsc_id in(%s)";
		this.executeUpdateByNative(String.format(sql, ids));
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ResourceDTO> findResourceForRole() {
		String sql="select r.RSC_ID,r.RSC_NAME,r.MU_ID,'false' as CHECKED from wits_resource r";
		return this.findByHibernateNative(ResourceDTO.class, sql);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ResourceDTO> findResourceForRole(String roleId) {
		String sql="select r.RSC_ID,r.RSC_NAME,r.MU_ID,case when rr.role_id='"+roleId+"' then 'true' else 'false' end as CHECKED"
				+" from wits_resource r left join wits_mmr_role_resource rr on(r.rsc_id=rr.rsc_id) and rr.role_id=?";
		return this.findByHibernateNative(ResourceDTO.class, sql, roleId);
	}

}
